package com.example.epidemic_assistant.ui;

import android.os.Bundle;
import android.widget.TextView;

import com.android.epidemic_assistant.gen.DaoSession;
import com.android.epidemic_assistant.gen.UserBeanDao;
import com.example.epidemic_assistant.App;
import com.example.epidemic_assistant.BaseActivity;
import com.example.epidemic_assistant.R;
import com.example.epidemic_assistant.bean.UserBean;

import java.util.ArrayList;
import java.util.List;

public class DeviceManagerDetailsActivity extends BaseActivity {

    private final static String TAG = "DeviceManagerDetailsActivity";

    private App mMyApp;
    private DaoSession mDaoSession;
    private UserBeanDao mUserBeanDao;
    private List<UserBean> mUserBeans;

    private List<UserBean> mUserBeanList;
    private List<Integer> mRoomIdList;
    private UserBean mUserBean;

    private TextView mTvRoomId;
    private TextView mTvName;
    private TextView mTvAge;
    private TextView mTvSex;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_device_manager_details);

        initView();
        initData();
        initListener();
    }

    private void initListener() {

    }

    private void initData() {
        Bundle extras = getIntent().getExtras();
        int position = extras.getInt("position");

        mMyApp = (App) this.getApplication();
        mDaoSession = mMyApp.getDaoSession();
        mUserBeanDao = mDaoSession.getUserBeanDao();
        mUserBeans = mUserBeanDao.loadAll();

        mUserBeanList = new ArrayList<>();
        mRoomIdList = new ArrayList<>();

        for (UserBean userBean : mUserBeans) {
            if (!userBean.isAdmin() && !mRoomIdList.contains(userBean.getRoomId()) && userBean.getIsMaintain() ) {
                mUserBeanList.add(userBean);
                mRoomIdList.add(userBean.getRoomId());
            }
        }

        mUserBean = mUserBeanList.get(position);
        mTvRoomId.setText(String.valueOf(mUserBean.getRoomId()));
        mTvName.setText(mUserBean.getName());
        mTvAge.setText(mUserBean.getAge());
        mTvSex.setText(mUserBean.getSex());
    }

    private void initView() {
        mTvRoomId = findViewById(R.id.tv_room_id);
        mTvName = findViewById(R.id.tv_name);
        mTvAge = findViewById(R.id.tv_age);
        mTvSex = findViewById(R.id.tv_sex);
    }
}